﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Raona.Code.Model
{
    /// <summary>
    /// A container for the default values of known types
    /// </summary>
    public class TypeDefaults
    {
        #region Class Fields (Private)

        /// <summary>
        /// A dictionnary containing the default values of known types
        /// </summary>
        private static Dictionary<string, string> defaultValuesCache = new Dictionary<string, string>(50);

        #endregion

        #region Class Constructor

        static TypeDefaults()
        {
            TypeDefaults.defaultValuesCache["bool"] = "Bool.Null";
            TypeDefaults.defaultValuesCache["System.Boolean"] = "Bool.Null";
            TypeDefaults.defaultValuesCache["byte"] = "Byt.Null";
            TypeDefaults.defaultValuesCache["System.Byte"] = "Byt.Null";
            TypeDefaults.defaultValuesCache["char"] = "Chr.Null";
            TypeDefaults.defaultValuesCache["System.Char"] = "Chr.Null";
            TypeDefaults.defaultValuesCache["System.DateTime"] = "Date.Null";
            TypeDefaults.defaultValuesCache["decimal"] = "Dec.Null";
            TypeDefaults.defaultValuesCache["System.Decimal"] = "Dec.Null";
            TypeDefaults.defaultValuesCache["double"] = "Dbl.Null";
            TypeDefaults.defaultValuesCache["System.Double"] = "Dbl.Null";
            TypeDefaults.defaultValuesCache["int"] = "Int.Null";
            TypeDefaults.defaultValuesCache["System.Int32"] = "Int.Null";
            TypeDefaults.defaultValuesCache["short"] = "Short.Null";
            TypeDefaults.defaultValuesCache["System.Int16"] = "Short.Null";
            TypeDefaults.defaultValuesCache["long"] = "Long.Null";
            TypeDefaults.defaultValuesCache["System.Int64"] = "Long.Null";
            TypeDefaults.defaultValuesCache["float"] = "Float.Null";
            TypeDefaults.defaultValuesCache["System.Single"] = "Float.Null";
        }

        #endregion

        #region Class Methods (Private)

        /// <summary>
        /// Returns the default value for the supplied type name
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public static string GetDefaultValue(string typeName)
        {
            string defaultValue = "null";
            string foundValue = null;
            if (TypeDefaults.defaultValuesCache.TryGetValue(typeName, out foundValue))
            {
                defaultValue = foundValue;
            }

            return defaultValue;
        }

        #endregion
    }
}
